#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
char s[5005];
char rs[5005];
int main() {
    int T;
    int m;
    cin>>T;
    while (T--) {
        scanf("%d", &m);
        scanf("%s", s);
        int len=strlen(s);
        for (int i=0; i<len; i++) rs[i] = s[len-i-1];
        int res=0;
        int res_st, res_en;
        for (int i=0; i<len; i++) {
            int st=0;
            int en=0;
            int cnt=0;
            while (cnt <= m && 2*en+i+2 <= len) {
                cnt+=abs(s[en] - rs[en+i]);
                ++en;
            }
            if (en-st>res) {
                res_st=st;
                res_en=en;
                res=en-st;
            }
            while (2*en+i+2 <= len) {
                cnt-=abs(s[st] - rs[st+i]);
                ++st;
                while (cnt <= m && 2*en+i+2 <= len) {
                    cnt+=abs(s[en] - rs[en+i]);
                    ++en;
                }
                if (en-st>res) {
                    res_st=st;
                    res_en=en;
                    res=en-st;
                }
            }
        }
        swap(s, rs);
        for (int i=0; i<len; i++) {
            int st=0;
            int en=0;
            int cnt=0;
            while (cnt <= m && 2*en+i+2 <= len) {
                cnt+=abs(s[en] - rs[en+i]);
                ++en;
            }
            if (en-st>res) {
                res_st=st;
                res_en=en;
                res=en-st;
            }
            while (2*en+i+2 <= len) {
                cnt-=abs(s[st] - rs[st+i]);
                ++st;
                while (cnt <= m && 2*en+i+2 <= len) {
                    cnt+=abs(s[en] - rs[en+i]);
                    ++en;
                }
                if (en-st>res) {
                    res_st=st;
                    res_en=en;
                    res=en-st;
                }
            }
        }
        cout<<res_st<<"---"<<res_en<<endl;
        printf("%d\n", res);
    }
    return 0;
}
